package com.atfcm.queue;

import java.util.LinkedList;
import java.util.Queue;

/**
 * @Author 96534
 * @create 2025/3/27 16:04
 *
 * 1 2 3
 * 4 5 6
 *
 */
public class T_225_队列实现栈 {

    Queue<Integer> queue1 = new LinkedList<Integer>();

    Queue<Integer> queue2 = new LinkedList<Integer>();

    public void push(int x) {
        queue2.offer(x);
        while (!queue1.isEmpty()) {
            queue2.offer(queue1.poll());
        }
        Queue<Integer> tmp =   queue1;
        queue1 = queue2;
        queue2 = tmp;
    }

    public int pop() {
        return queue1.poll();
    }

    public int top() {
        return queue1.peek();
    }

    public boolean empty() {
        return queue1.isEmpty();
    }
}
